
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author me
 */
import java.sql.*;
public class NewMain {


   
     public static void main (String args[]) {
       try {
 // Carichiamo un driver di tipo 1 (bridge jdbc-odbc)
         String driver = "com.mysql.jdbc.Driver";
         Class.forName(driver);
 // Creiamo la stringa di connessione
         String url = "jdbc:mysql://localhost:3306/test";
 // Otteniamo una connessione con username e password
        Connection con = DriverManager.getConnection (url, "root", "");
 // Creiamo un oggetto Statement per poter interrogare il db
        Statement cmd = con.createStatement ();
 // Eseguiamo una query e immagazziniamone i risultati
 // in un oggetto ResultSet
        String qry = "SELECT * FROM employeeinfo";
        ResultSet res = cmd.executeQuery(qry);
        
        //String ins = "INSERT INTO employeeinfo VALUES ('a','b')";
        //cmd.executeUpdate(ins);
 // Stampiamone i risultati riga per riga
        while (res.next()) {
        System.out.println(res.getString("name"));
        System.out.println(res.getString("surname"));
      }
        String ins = "INSERT INTO employeeinfo VALUES (90,'a','b',10)";
        cmd.executeUpdate(ins);
      res.close();
      cmd.close();
      con.close();
   } catch (SQLException e) {
         e.printStackTrace();
    } catch (ClassNotFoundException e) {
         e.printStackTrace();
       }
    }
  }
   
    /*public static void main(String[] args) {
          String url = "jdbc:mysql://localhost:3306/";
          String dbName = "test";
          String driver = "com.mysql.jdbc.Driver";
          String userName = "root";
          String password;
        password = "";
          try {
          Class.forName(driver).newInstance();
          Connection conn = DriverManager.getConnection(url+dbName,userName,password);
          Statement st = conn.createStatement();
          ResultSet res = st.executeQuery("SELECT * FROM  employeeinfo");
          while (res.next()) {
          int id = res.getInt("employeeid");
          String msg = res.getString("msg");
          System.out.println(id + "\t" + msg);
          }
          int val = st.executeUpdate("INSERT into event VALUES("+1+","+"'Easy'"+")");
          if(val==1)
              System.out.print("Successfully inserted value");
          conn.close();
          } catch (Exception e) {
          e.printStackTrace();
          }
          }
}
    */
